Repository navigation
fix: validate Unicode escapes of PostgreSQL escape strings - #2861
Merged
manticore-projects merged 1 commit intoOct 27, 2026
Merged
manticore-projects merged 1 commit into
manticore-projects merged 1 commit into
Conversation
With Dialect.POSTGRESQL, StringValue.getNotExcapedValue resolved the \uXXXX and \UXXXXXXXX escapes of an E'...' string with Integer.parseInt and StringBuilder.appendCodePoint and no range or surrogate check, so E'\uD800' produced an unpaired surrogate, E'\u0000' a NUL, E'\U00110000' threw from StringBuilder and E'\UFFFFFFFF' a NumberFormatException, while the parser accepted them all. PostgreSQL rejects each of them. Decode the E'' Unicode escapes with the rules the U&'' path already applies: exactly 4 or 8 hexadecimal digits, no code point zero or value above U+10FFFF, and a surrogate pair only as two consecutive escapes. The parser rejects such a literal under the PostgreSQL dialect as it does for U&'' strings.
Contributor
|
Thank you very much! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
With Dialect.POSTGRESQL, StringValue.getNotExcapedValue resolves the \uXXXX and \UXXXXXXXX escapes of an E'...' string with Integer.parseInt and StringBuilder.appendCodePoint, with no range or surrogate check, while the U&'...' path added in #2820 already validates the same escapes the way the server does. So E'\uD800' comes back as a lone surrogate (an ill-formed string that turns into U+FFFD or '?' once it is encoded), E'\u0000' yields a NUL the server refuses, E'\U00110000' throws from StringBuilder, E'\UFFFFFFFF' throws NumberFormatException, and the parser accepts every one of them. I noticed it while comparing the two decoders after the U&'' change. The E'' Unicode escapes now go through the same code point and surrogate pair rules as the U&'' escapes: a pair must be two consecutive escapes, in either form, and too few digits, code point zero, anything above U+10FFFF and an unpaired surrogate raise the documented IllegalArgumentException. stringValue() in the grammar checks an escape string under the PostgreSQL dialect the way lexUnicodeEscapeString does for U&'' strings, so such a literal is a parse error as on the server. Standard strings and the other dialects are unchanged, and the regression test in StringValueTest covers the accepted and rejected forms.